package com.wnxy.pawnbackgroundsystem.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.pawnbackgroundsystem.dto.GetStoreNameDto;
import com.wnxy.pawnbackgroundsystem.dto.InsertStoreDto;
import com.wnxy.pawnbackgroundsystem.dto.StoreDto;
import com.wnxy.pawnbackgroundsystem.entity.Store;
import com.wnxy.pawnbackgroundsystem.param.GetStoreParam;
import com.wnxy.pawnbackgroundsystem.param.InsertStoreParam;
import com.wnxy.pawnbackgroundsystem.param.UpdateStoreParam;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.IStoreService;
import com.wnxy.pawnbackgroundsystem.service.impl.StoreServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 门店管理表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-14
 */
@RestController
@RequestMapping("/pawnbackgroundsystem/store")
@Api(tags = "门店管理接口")
@CrossOrigin("*")
public class StoreController {
    @Resource
    private IStoreService storeService;


    @ApiOperation("新增门店")
    @PostMapping("/insertStore")
    public Result insertStore(@RequestBody InsertStoreParam isp){
        storeService.insertStore(isp);
        return new Result(true,"2002","新增成功",null);
    }

    @ApiOperation("删除商店")
    @GetMapping("/delStore")
    public Result delStore(Integer storeId){
        storeService.delStore(storeId);
        return new Result(true,"2002","删除成功",null);
    }

    @ApiOperation("查询所有门店")
    @GetMapping("/getStore")
    public Result getStore(){
        List<Store> stores=storeService.getStore();
        return new Result(true,"2002","查询成功",stores);
    }
    @ApiOperation("分页模糊查询")
    @PostMapping("/selectStore")
    public Result selectStore(@RequestBody GetStoreParam getStoreParam){
        System.out.println("----------");
        System.out.println(getStoreParam);
        IPage<StoreDto> storeDtoIPage = storeService.storeDto(getStoreParam);

        return  new Result(true,"2002","查询成功",storeDtoIPage);
    }

    @ApiOperation("门店修改")
    @PostMapping("/updeteStore")
    public Result updeteStore(@RequestBody UpdateStoreParam updateStoreParam){
        storeService.updeteStore(updateStoreParam);
        return new Result(true,"2002","修改成功",null);
    }

    @GetMapping("/GetStoreNameDto")
    public Result getAllHouse() {
        List<GetStoreNameDto> allHouse = storeService.getAllHouse();
        return new Result(true,"2002","修改成功",allHouse);
    }


    @ApiOperation("/修改门店获取对应关联仓库")
    @GetMapping("/getStoreName")
    public Result getStoreName(Integer storeId){
        System.out.println("----------");
        System.out.println(storeId);
        List<String> houseName=storeService.getWareHouseName(storeId);

        return new Result(true,"2002","查询集合成功",houseName);
    }


}

